<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        ul {
            list-style: none;
        }

        html,
        body {
            width: 100%;
            height: 100%;
            display: flex;
        }

        .left {
            width: 60%;
            height: 100%;
            background-color: palegoldenrod;
        }

        ul {
            width: 100%;
            height: 100%;
            display: flex;
            flex-wrap: wrap;
        }

        .right {
            width: 40%;
            height: 100%;
            background-color: paleturquoise;
        }

        .xiam {
            width: 100%;
            height: 100%;
        }

        li {
            display: block;
            width: 24%;
            margin-right: 1%;
            height: 50%;
            background-color: antiquewhite;
        }

        img {
            width: 100%;
            height: 70%;
        }

        h2 {
            font-weight: normal;
            display: block;
            margin-left: 20px;
            font-size: 16px;
        }

        p {
            display: block;
            margin-left: 20px;
            font-size: 16px;
        }

        button {
            display: block;
            margin-left: 20px;
            font-size: 16px;
            background-color: red;
            border: 1px solid black;
            width: 100px;
            height: 30px;
            line-height: 30px;
            text-align: center;
            color: white;
        }

        .oro {
            display: inline-block;
            width: 100px;
            height: 100px;
            vertical-align: middle;
        }

        span {
            padding-left: 50px;
        }

        .pop {
            display: block;
            padding: 20px;
        }
    </style>
</head>

<body>
    <div class="left">
        <ul>
            <!-- <li>
                <img src="img/1.png" alt="">
                <h2>高级办公椅</h2>
                <p>10000</p>
                <button>加入购物车</button>
            </li>
            <li>
                <img src="img/2.png" alt="">
                <h2>高级按摩椅</h2>
                <p>1000</p>
                <button>加入购物车</button>
            </li>
            <li>
                <img src="img/3.png" alt="">
                <h2>高级电动按摩椅</h2>
                <p>100</p>
                <button>加入购物车</button>
            </li>
            <li>
                <img src="img/4.png" alt="">
                <h2>电动按摩椅</h2>
                <p>10</p>
                <button>加入购物车</button>
            </li>
            <li>
                <img src="img/5.png" alt="">
                <h2>老板椅</h2>
                <p>20000</p>
                <button>加入购物车</button>
            </li>
            <li>
                <img src="img/6.png" alt="">
                <h2>办公桌</h2>
                <p>50000</p>
                <button>加入购物车</button>
            </li>
            <li>
                <img src="img/7.png" alt="">
                <h2>可升降办公椅</h2>
                <p>5000</p>
                <button>加入购物车</button>
            </li>
            <li>
                <img src="img/8.png" alt="">
                <h2>可升降办公桌</h2>
                <p>2000</p>
                <button>加入购物车</button>
            </li> -->
        </ul>
    </div>
    <div class="right">
        <h3>购物车</h3>
        <div class="xiam">
            <!-- <input type="checkbox">
        <img src="img/1.png" alt="" class="oro">
        <span>10</span>
        <span>1</span>
        <span>删除收藏</span>
        <span class="pop">电动按摩椅</span>

        <input type="checkbox">
        <img src="img/1.png" alt="" class="oro">
        <span>10</span>
        <span>1</span>
        <span>删除收藏</span>
        <span class="pop">电动按摩椅</span>


        <input type="checkbox">
        <img src="img/1.png" alt="" class="oro">
        <span>10</span>
        <span>1</span>
        <span>删除收藏</span>
        <span class="pop">电动按摩椅</span> -->
        </div>

    </div>
</body>

</html>
<script>
    var uls = document.querySelector('ul')
    var dataList = [
        { 'pic': "img/1.png", 'h2': '高级办公椅', 'p': 10000 },
        { 'pic': "img/2.png", 'h2': '高级按摩椅', 'p': 1000 },
        { 'pic': "img/3.png", 'h2': '高级电动按摩椅', 'p': 100 },
        { 'pic': "img/4.png", 'h2': '电动按摩椅', 'p': 10 },
        { 'pic': "img/5.png", 'h2': '老板椅', 'p': 20000 },
        { 'pic': "img/6.png", 'h2': '办公桌', 'p': 50000 },
        { 'pic': "img/7.png", 'h2': '可升降办公椅', 'p': 5000 },
        { 'pic': "img/8.png", 'h2': '可升降办公桌', 'p': 2000 }

    ]
    var str = ``
    for (let i = 0; i < dataList.length; i++) {
        str += `
            <li>
                <img src=${dataList[i].pic} alt="">
                <h2>${dataList[i].h2}</h2>
                <p>${dataList[i].p}</p>
                <button class="btn">加入购物车</button>
            </li>
            `

    }
    uls.innerHTML = str

    // var rig =document.querySelector('.right')
    var xia = document.querySelector('.xiam')
    var btns = document.querySelectorAll('.btn')
    var count = 0
    for (let i = 0; i < btns.length; i++) {
        // count += i.count
        btns[i].index = i
        var str1 = ``
        var arr = []
        // var flag = true
        btns[i].onclick = function () {
            // count++  
            var s = dataList[i].pic
                if (s != null) {
                console.log(s);
                } else {
                    str1 += `
                <input type="checkbox">
                <img src=${dataList[i].pic} alt="" class="oro">
                <span>${dataList[i].p}</span>
                <span>${count}</span>
                <span>删除收藏</span>
                <span class="pop">${dataList[i].h2}</span>
            `

                    xia.innerHTML = str1

                }


        }
    }



</script>